﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Terminal.Advanced_AEUC_settings_controls.Settings_AUX;

namespace Terminal.Advanced_AEUC_settings_controls.Scripting
{
    class ScrCondElif : ScrBasicAction
    {
        /// <summary>
        /// Public constructor for the script action
        /// </summary>
        /// <param name="iDispName">Action display text</param>
        /// <param name="iUsageHelp">Usage help and comments text for the action</param>
        public ScrCondElif(string iDispName, string iUsageHelp)
            : base(iDispName, iUsageHelp)
        {
            usageHelp += "Input params: Integer evaluated expression + Conditional opperator (<,>,==,!=,...) + Integer evaluated expression\n";
        }

        /// <summary>
        /// Perform the action using specified parameters.
        /// </summary>
        /// <param name="paramList">List of the input/output parameters for the action</param>
        /// <returns>True if action is succesful</returns>
        public override bool Do(List<object> paramList)
        {
            if (breakPoint)
                WaitUserInput();

            if (paramList.Count > 1 && paramList[0].GetType() == typeof(ScrRunTimeEnv) && paramList[1].GetType() == typeof(int))
            {
                ScrRunTimeEnv rte = (ScrRunTimeEnv)(paramList[0]);
                Int32 boolVal = (Int32)(paramList[1]);

                if (boolVal >= 1)
                    rte.condExecution = ScrRunTimeEnv.CondExecMode.EXEC_IF;
                else
                    rte.condExecution = ScrRunTimeEnv.CondExecMode.SKIP_IF;

                return true;
            }

            return false;
        }

        /// <summary>
        /// Generate C source code for specified parameters
        /// </summary>
        /// <param name="paramlist">List of input/output parameters for the action</param>
        /// <returns>C source string</returns>
        public override string GenerateSourceCode(List<object> paramList)
        {
            string c_source = "Can't generate source - check script file!";

            if (paramList.Count > 0)
            {
                string condition = (string)(paramList[0]);

                c_source += "\t}\n";
                c_source = "\telse if(" + condition + ")\n";
                c_source += "\t{\n";
            }

            return c_source;
        }

        /// <summary>
        /// Returns a List containing objects of the parameter list required for the Do function.
        /// </summary>
        /// <returns>List of parameter objects</returns>
        public override List<Type> GetParamList()
        {
            List<Type> paramList = new List<Type>();
            paramList.Add(typeof(ScrRunTimeEnv));
            paramList.Add(typeof(int));

            return paramList;
        }

        /// <summary>
        /// Returns a List containing objects of the parameter list required for the GenerateSourceCode function.
        /// </summary>
        /// <returns>List of parameter objects</returns>
        public override List<Type> GetParamListSourceGen()
        {
            List<Type> paramList = new List<Type>();
            paramList.Add(typeof(ScrRunTimeEnv));
            paramList.Add(typeof(string));

            return paramList;
        }
    }
}